#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
vector<vector<int>> fourSum(vector<int>& nums, int target) {
    short size=nums.size();
    short m,k;
    vector<vector<int>>result;
    sort(nums.begin(),nums.end());
//    for(auto temp:nums){
//        cout<<temp<<",";
//    }
//    cout<<"\n";
    for(short i=0;i<=size-4;i++){
        if(i!=0&&nums[i]==nums[i-1]) continue;
            for (short j = i + 1; j <= size - 3; j++) {
                if(j!=i+1&&nums[j]==nums[j-1]) {
//                    cout<<i<<","<<j<<endl;
                    continue;
                }
                    m = j + 1;
                    k = size - 1;
                    while (m < k) {
//                        cout<<nums[i]<<","<<nums[j]<<","<<nums[m]<<","<<nums[k]<<endl;
                        if (nums[i] + nums[j] + nums[m] + nums[k] < target) {
                            m++;
                        } else if (nums[i] + nums[j] + nums[m] + nums[k] > target) {
                            k--;
                        } else {
//                            cout<<"push"<<endl;
                            result.push_back({nums[i], nums[j], nums[m], nums[k]});
                            m++;
                            k--;
                            while(nums[m]==nums[m-1]||nums[k]==nums[k+1]){
                                if(nums[m]==nums[m-1])m++;
                                if(nums[k]==nums[k+1])k--;
                            }
                        }
                    }
            }
    }
    return result;
}


int main(){
//    vector<int>b={-3,-2,-1,0,0,1,2,3};
//    vector<int>b={-1,0,-5,-2,-2,-4,0,1,-2};
    vector<int>b={0,0,0,0};
    vector<vector<int>>a=fourSum(b,0);
    for(auto temp:a){
        for(short i=0;i<temp.size();i++){
            cout<<temp[i]<<",";
        }
        cout<<endl;
    }

    return 0;
}